package com.rqbl.service.impl;

import com.rqbl.entity.Bar;
import com.rqbl.mapper.BarMapper;
import com.rqbl.myutils.PageBean;
import com.rqbl.service.BarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BarServiceImpl implements BarService {

    @Autowired
    private BarMapper barMapper;

    @Override
    public List<Bar> getBarByPage(PageBean pageBean) {
        pageBean.setTotalSize(barMapper.selectAllBarCount());
        int totalPage = pageBean.getTotalSize() / pageBean.getPageSize();
        if(pageBean.getTotalSize() % pageBean.getPageSize() != 0) {
            totalPage++;
        }
        pageBean.setTotalPage(totalPage);
        return barMapper.selectAllBarPage((pageBean.getPage()-1)*pageBean.getPageSize(), pageBean.getPageSize());
    }

    @Override
    public Integer addBar(Bar bar) {
        barMapper.insertBar(bar);
        return bar.getBid();
    }

    @Override
    public Bar getBarById(Integer bid) {
        return barMapper.selectBarById(bid);
    }

    @Override
    public List<Bar> getAllBarByUid(Integer uid) {
        return barMapper.selectAllBarByUid(uid);
    }

    @Override
    public Integer updateBarAnnounce(Integer bid, String announce) {
        return barMapper.updateBarAnnounce(bid, announce);
    }

    @Override
    public Integer updateBarImgByBid(Integer bid, String url) {
        return barMapper.updateBarImgByBid(bid, url);
    }

    @Override
    public Integer updateBarInfo(Integer bid, String bname, String bdescribe) {
        return barMapper.updateBarInfo(bid, bname, bdescribe);
    }

}
